Public Class OrderHistoryReportByProductCtrl
    Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents litTbody As System.Web.UI.WebControls.Literal
    Protected WithEvents litTotal As System.Web.UI.WebControls.Literal

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private TR_START_TAG As String = "<TR>"
    Private TR_END_TAG As String = "</TR>"
    Private TD_START_TAG As String = "<TD"
    Private TD_CLASS As String = "class=bgrow1"
    Private TD_ALIGN_CENTER As String = "align=center"
    Private TD_ALIGN_RIGHT As String = "align=right"
    Private TD_CLOSED_TAG As String = ">"
    Private TD_END_TAG As String = "</TD>"

#Region " Properties"
    Public Property DataReport() As DataTable
        Get
            Return CType(ViewState("DataReport"), DataTable)
        End Get
        Set(ByVal Value As DataTable)
            ViewState("DataReport") = Value
        End Set
    End Property

    Public Property Total() As Integer
        Get
            If Not ViewState("Total") Is Nothing Then
                Return CInt(ViewState("Total"))
            Else
                Return 0
            End If
        End Get
        Set(ByVal Value As Integer)
            ViewState("Total") = Value
        End Set
    End Property

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here        
    End Sub

    Public Sub GenerateReport()
        Me.Total = 0

        litTbody.Text = Me.GetTBodyHTML()
        litTotal.Text = Me.Total.ToString()
    End Sub

    Public Function GetTBodyHTML() As String
        Dim str As New System.Text.StringBuilder
        Dim row As DataRow

        For Each row In DataReport.Rows
            str.Append(Me.TR_START_TAG)
            str.Append(Me.GetProductColumn(CStr(row.Item(0)))) ' Production Number
            str.Append(Me.GetProductColumn(CStr(row.Item(1)))) ' Production Description
            Dim quantity As Integer = CInt(row.Item(2))
            str.Append(Me.GetQuantityColumn(CStr(quantity)))
            str.Append(Me.GetBarCodeColumn(CStr(row.Item(3)), CStr(row.Item(4)), CStr(row.Item(5))))
            str.Append(Me.GetColorColumn(CStr(row.Item(6))))
            str.Append(Me.GetPackColumn(CStr(row.Item(7))))
            Me.Total = Me.Total + quantity
            str.Append(Me.TR_END_TAG)
        Next

        Return str.ToString()
    End Function
    Private Function GetProductColumn(ByVal data As String) As String
        Dim str As New System.Text.StringBuilder

        str.Append(Me.TD_START_TAG + " ")
        str.Append(Me.TD_ALIGN_CENTER + " ")
        str.Append(Me.TD_CLASS + " ")
        str.Append(Me.TD_CLOSED_TAG)
        str.Append(data)
        str.Append(Me.TD_END_TAG)

        Return str.ToString()
    End Function

    Private Function GetQuantityColumn(ByVal data As String) As String
        Dim str As New System.Text.StringBuilder

        str.Append(Me.TD_START_TAG + " ")
        str.Append(Me.TD_ALIGN_RIGHT + " ")
        str.Append(Me.TD_CLASS + " ")
        str.Append(Me.TD_CLOSED_TAG)
        str.Append(data)
        str.Append(Me.TD_END_TAG)

        Return str.ToString()
    End Function

    Private Function GetBarCodeColumn(ByVal country As String, ByVal customerBarCode As String, ByVal partOfBarcode As String) As String
        Dim str As New System.Text.StringBuilder

        Dim data As String

        data = COrderItem.GetBarCode(country = COrderItem.CONST_UNITED_STATES_COUNTRY, customerBarCode, partOfBarcode)

        str.Append(Me.TD_START_TAG + " ")
        str.Append(Me.TD_ALIGN_CENTER + " ")
        str.Append(Me.TD_CLASS + " ")
        str.Append(Me.TD_CLOSED_TAG)
        str.Append(customerBarCode & " " & data)
        str.Append(Me.TD_END_TAG)

        Return str.ToString()
    End Function

    Private Function GetColorColumn(ByVal data As String) As String
        Dim str As New System.Text.StringBuilder

        str.Append(Me.TD_START_TAG + " ")
        str.Append(Me.TD_ALIGN_CENTER + " ")
        str.Append(Me.TD_CLASS + " ")
        str.Append(Me.TD_CLOSED_TAG)
        str.Append(data)
        str.Append(Me.TD_END_TAG)

        Return str.ToString()
    End Function

    Private Function GetPackColumn(ByVal data As String) As String
        Dim str As New System.Text.StringBuilder

        str.Append(Me.TD_START_TAG + " ")
        str.Append(Me.TD_ALIGN_CENTER + " ")
        str.Append(Me.TD_CLASS + " ")
        str.Append(Me.TD_CLOSED_TAG)
        str.Append(data)
        str.Append(Me.TD_END_TAG)

        Return str.ToString()
    End Function

End Class
